package com.vains.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.vains.entity.OauthPermission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 资源表 Mapper 接口
 * </p>
 *
 * @author vains
 * @since 2020-06-08
 */
public interface OauthPermissionMapper extends BaseMapper<OauthPermission> {

    /**
     * 根据用户ID获取对应的权限
     * @param userId 用户ID
     * @return 权限列表
     */
    @Select("SELECT op.* FROM oauth_user ou, oauth_user_role our, oauth_role `or`, oauth_role_permission orp, oauth_permission op WHERE ou.user_id = our.user_id AND our.role_id = `or`.role_id AND `or`.role_id = orp.role_id AND orp.permission_id = op.permission_id AND ou.user_id = #{userId} AND op.permission_type = 1")
    List<OauthPermission> getPermissionsByUserId(@Param("userId") Integer userId);
}
